package sb.de.advanceShopper.activities;

import sb.de.advanceShopper.R;
import sb.de.advanceShopper.dataBase.CitiesDataSource;
import sb.de.advanceShopper.dataBase.ShopsDataSource;
import sb.de.advanceShopper.model.City;
import sb.de.advanceShopper.model.Country;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Spinner;

public class AddShopActivity extends Activity {

	private ShopsDataSource shopsDS;
	private CitiesDataSource citiesDS;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.add_shop);

		shopsDS = new ShopsDataSource(this);
		citiesDS = new CitiesDataSource(this);

		Spinner landSpinner = (Spinner) findViewById(R.id.spinner1);
		ArrayAdapter<Country> adapter = new ArrayAdapter<Country>(this,
				android.R.layout.simple_spinner_dropdown_item,
				AdvanceShopperActivity.COUNTRIES);
		adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		landSpinner.setAdapter(adapter);
		// List<Shop> values = ds.getAllShops();
	}

	public void addShop(View v) {
		String name = ((EditText) findViewById(R.id.editText1)).getText()
				.toString();

		// TODO implement it without Country object (only ID)
		String countryName = ((EditText) findViewById(R.id.editText2))
				.getText().toString();
		Country country = AdvanceShopperActivity.getCountryByName(countryName);

		// TODO implement it without City object (only ID)
		String cityName = ((EditText) findViewById(R.id.editText3)).getText()
				.toString();
		City city = citiesDS.getCityByName(cityName, country.getId());

		String description = ((EditText) findViewById(R.id.editText4))
				.getText().toString();
		shopsDS.createShop(name, city, description);
	}

}
